package com.crowdsourcing.service.impl;

import com.crowdsourcing.dao.UserMapper;
import com.crowdsourcing.model.User;
import com.crowdsourcing.model.UserExample;
import com.crowdsourcing.service.IUserServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements IUserServcie {
    @Autowired
    UserMapper userMapper;

    @Override
    public User login(User user) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andUsernameEqualTo(user.getUsername());
        criteria.andPasswordEqualTo(user.getPassword());
        criteria.andTypeEqualTo(user.getType());
        List<User> users = userMapper.selectByExample(userExample);
        if(users.size()==1){
            return users.get(0);
        }
        else{
            return null;
        }

    }
}
